package com.liangzai.spring.demo.controller;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserLoginController {

    @RequestMapping("/login")
    public boolean login(String userName, String passWord, HttpSession session){
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(passWord)){
            return false;
        }
        if("admin".equals(userName) && "admin".equals(passWord)){
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }

    @RequestMapping("/getUser")
    public String getData(HttpSession session){
        String userName = (String)session.getAttribute("userName");
        System.out.println(userName);
        return userName;
    }
}
